import sys
file = open("input.txt")
data = file.readlines()
N = int(data[0])
box = [0] + list(map(int, data[1].split()))
gas = [[] for i in range(max(box) + 1)]
for i in range(1, N + 1):
    gas[box[i]] += [i]
i = N
j = N
ans = 0
planets = []
if gas[box[-1]] == list(range(gas[box[-1]][0], gas[box[-1]][-1] + 1)) and len(gas[box[-1]]) != N:
    print(0)
    sys.exit()
while i > 1:
    visited = set()
    starts = []
    for t in range(i, j + 1):
        if box[t] not in visited and gas[box[t]][0] < i:
            while j >= gas[box[t]][-1] >= i:
                gas[box[t]].pop()
            visited.add(box[t])
            starts += [gas[box[t]][-1]]
    j = i - 1
    i = min(starts)
    ans += 1
    planets += [i]
print(ans)
print(' '.join(map(str, planets[::-1])))
